﻿<div ng-controller="productActivityController" style="width:130%;">
    <div class="wrapper border-bottom white-bg page-heading">
        <div class="col-lg-pull-12">
            <ol class="breadcrumb">
                <li><a href="javascript:void(0)" ng-click="goBack()">活动</a></li>
                <li class="active" ng-bind="breadcrumb">商品设置</li>
            </ol>
        </div>
    </div>
    <form name="_form" class="form-horizontal w5c-form" w5c-form-validate="model.validateOptions" role="form" novalidate>
        <div class="form-group form-group-sm">
            <div class="col-sm-10">
                <button ng-if="model.activity.status != 2" class="btn btn-primary btn-sm" ng-click="addGood()"><i class="fa fa-plus"></i>添加商品</button>
            </div>
            <div class="col-sm-2">
                <button class="btn btn-primary btn-sm" ng-click="open_set_data()">批量设置比例跟数量</button>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-12">
                <table class="table table-hover">
                    <thead>
                        <tr>
                            <th width="50">序号</th>
                            <th width="100">商品名称</th>
                            <th width="50">规格</th>
                            <th width="50">原价</th>
                            <th ng-if="model.activity.type == 3" width="100">活动价</th>
                            <th ng-if="model.activity.type == 4" width="250">活动价(现金+红钻)</th>
                            <th ng-if="model.activity.type == 5" width="100">活动价(红钻)</th>
                            <th ng-if="model.activity.type == 3" width="100">结算价</th>
                            <th ng-if="model.activity.type == 4" width="150">结算价(现金+红钻)</th>
                            <!--<th ng-if="model.activity.type == 5" width="100">结算价(红钻)</th>-->
                            <th ng-if="model.activity.type != 5" width="50">分销比例</th>
                            <th width="50">每单最小购买数（件）</th>
                            <th ng-if="model.activity.type == 3" width="100">实际价格</th>
                            <th ng-if="model.activity.type == 4" width="100">实际价格(现金+红钻/纯现金)</th>
                            <th ng-if="model.activity.type == 5" width="100">实际价格(红钻)</th>
                            <th ng-if="model.activity.type == 3" width="100">分佣金额</th>
                            <th ng-if="model.activity.type == 4" width="100">分佣金额(现金+红钻/纯现金)</th>
                            <th width="50">{{model.activity.type == 5 ? "每人最大购买数（件）" :"每单最大购买数（次）"}} </th>
                            <th width="80">活动库存</th>
                            <th width="80">马力数量（个）</th>
                            <th width="80">马力有效时间（天）</th>
                            <th width="80">排序</th>
                            <th ng-if="model.activity.status == 2" width="50">销售数量</th>
                            <th ng-if="model.activity.status != 2" width="50">操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr ng-repeat="(key,item) in model.list  track by $index">
                            <td>{{$index+1}}</td>
                            <td>{{item.product_name}}</td>
                            <td>{{item.product_sku_name}}</td>
                            <td>{{item.product_price}}</td>
                            <td ng-if="model.activity.type == 3"><input ng-model="item.activity_price" class="form-control input-sm" w5c-dynamic-name2="item.activity_price_{{key}}" type="number" min="0" required /></td>
                            <td ng-if="model.activity.type == 4">
                                <input ng-model="item.activity_price" class="form-control input-sm" w5c-dynamic-name2="item.activity_price_{{key}}" type="number" min="0" style="width:40%;display:inline-block;" required /> +
                                <input ng-model="item.activity_red_drill" class="form-control input-sm" w5c-dynamic-name2="item.activity_red_drill_{{key}}" type="number" min="0" style="width:40%;display:inline-block;" required />
                            </td>
                            <td ng-if="model.activity.type == 5"><input ng-model="item.activity_red_drill" class="form-control input-sm" w5c-dynamic-name2="item.activity_red_drill_{{key}}" type="number" min="0" required /></td>

                            <td ng-if="model.activity.type == 3"><input ng-model="item.cost_price" class="form-control input-sm" w5c-dynamic-name2="item.cost_price_{{key}}" type="number" min="0" required /></td>
                            <td ng-if="model.activity.type == 4">
                                <input ng-model="item.cost_price" class="form-control input-sm" w5c-dynamic-name2="item.cost_price_{{key}}" type="number" min="0" required style="width:60%;display:inline-block" /> +
                                {{item.activity_red_drill == null ? 0 :item.activity_red_drill}}
                            </td>
                            <!--<td ng-if="model.activity.type == 5">{{item.activity_red_drill}}</td>-->

                            <td ng-if="model.activity.type != 5">{{item.distribution_rate}}</td>

                            <td>
                                <input ng-model="item.min_buy_mum" class="form-control input-sm" w5c-dynamic-name2="item.min_buy_mum_{{key}}" min="1" step="1" required
                                       onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" />
                            </td>

                            <td ng-if="model.activity.type == 3">{{(item.activity_price != null && item.min_buy_mum != null) ? item.activity_price * item.min_buy_mum : ''}}</td>
                            <td ng-if="model.activity.type == 4">
                                {{(item.activity_price != null && item.min_buy_mum != null) ? item.activity_price * item.min_buy_mum : 0}}+{{(item.activity_red_drill != null && item.min_buy_mum != null) ? item.activity_red_drill * item.min_buy_mum : 0}}
                                /{{(item.product_price != null && item.min_buy_mum != null) ? item.product_price * item.min_buy_mum : 0}}
                            </td>
                            <td ng-if="model.activity.type == 5">{{(item.activity_red_drill != null && item.min_buy_mum != null) ? item.activity_red_drill * item.min_buy_mum : ''}}</td>

                            <td ng-if="model.activity.type == 3">{{(item.activity_price != null && item.min_buy_mum != null && item.cost_price != null) ? ((item.activity_price - item.cost_price) * item.min_buy_mum * item.distribution_rate).toFixed(2) : ''}}</td>
                            <td ng-if="model.activity.type == 4">
                                {{(item.activity_price != null && item.min_buy_mum != null && item.cost_price != null) ? ((item.activity_price - item.cost_price) * item.min_buy_mum * item.distribution_rate).toFixed(2) : 0}}
                                +{{(item.activity_red_drill != null && item.min_buy_mum != null) ? item.activity_red_drill * item.min_buy_mum : 0}}
                                /{{(item.product_price != null && item.min_buy_mum != null && item.raw_cost_price != null) ? ((item.product_price - item.raw_cost_price) * item.min_buy_mum * item.distribution_rate).toFixed(2) : 0}}
                            </td>

                            <td>
                                <input ng-model="item.max_buy_num" class="form-control input-sm" w5c-dynamic-name2="item.max_buy_num_{{key}}" min="0" step="1" required
                                       onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^0-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^0-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" />
                            </td>
                            <td>
                                <input ng-model="item.activity_stock" class="form-control input-sm" w5c-dynamic-name2="item.activity_stock_{{key}}" min="0" step="1" required
                                       onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^0-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^0-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" />
                            </td>
                            <td>
                                <input ng-model="item.horse_power" class="form-control input-sm" w5c-dynamic-name2="item.horse_power_{{key}}" min="0" step="1" required
                                       onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^0-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^0-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" />
                            </td>
                            <td><input ng-model="item.horse_power_effective" class="form-control input-sm" w5c-dynamic-name2="item.horse_power_effective_{{key}}" /></td>
                            <td>
                                <input ng-model="item.top" class="form-control input-sm" w5c-dynamic-name2="item.top_{{key}}" min="0" step="1" required
                                       onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^0-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^0-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" />
                            </td>
                            <td ng-if="model.activity.status == 2">{{item.sale_count}}</td>
                            <td ng-if="model.activity.status != 2">
                                <a ng-if="item.product_activity_id > 0 && !item.is_sold_out" class="btn btn-primary btn-xs" ng-click="sale_out_product(item.product_activity_id, 1)"><i class="fa fa-trash"></i> 售尽</a>
                                <a ng-if="model.activity.status == 0 ||item.product_activity_id == null || item.product_activity_id == 0" class="btn btn-primary btn-xs" ng-click="delete_product(item.product_id, item.product_sku_id)"><i class="fa fa-trash"></i> 删除</a>

                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
        <div class="form-group form-group-sm">
            <label class="col-sm-2 control-label"></label>
            <div class="col-sm-3">
                <button ng-if="model.activity.status != 2" type="submit" w5c-form-submit="save()" class="btn btn-primary btn-sm" btn-loading="psdisabled.save" loading-text="保存中..." ng-disabled="psdisabled.save">
                    <i class="fa fa-save"></i> 保存
                </button>
                <button ng-click="goBack()" class="btn btn-primary btn-sm"><i class="fa fa-rotate-left"></i> 取消</button>
            </div>
        </div>
    </form>
</div>



<script type="text/ng-template" id="modal.html">
    <p>
    <p class="modal-header"><h5 class="modal-title" align="center">商品列表</h5></p>
    <form class="form-horizontal row">
        <div class="form-group">
            <div class="col-sm-4">
                <label class="col-sm-3 control-label">商品名称</label>
                <div class="col-sm-9">
                    <input name="keyword" type="text" class="form-control input-sm" ng-model="keyword">
                </div>
            </div>
            <div class="col-sm-5">
                <label class="col-sm-3 control-label">价格</label>
                <div class="col-sm-4">
                    <input name="min_price" type="number" class="form-control input-sm" ng-model="min_price">
                </div>
                <div class="col-sm-1">～</div>
                <div class="col-sm-4">
                    <input name="max_price" type="number" class="form-control input-sm" ng-model="max_price">
                </div>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-4">
                <div class="col-sm-offset-4 col-sm-8">
                    <button class="btn btn-primary btn-sm" ng-click="getProducts()"><i class="fa fa-search"></i> 查询</button>
                </div>
            </div>
        </div>
    </form>
    <table class="table table-hover m-t-md">
        <thead>
            <tr>
                <th width="50"></th>
                <th>图片</th>
                <th width="100">名称 价格</th>
                <th width="300">描述</th>
                <th width="50">库存</th>
                <th width="50">所属账号</th>
                <th width="50">销售状态</th>
                <th width="50">审核状态</th>
                <th width="100">添加时间</th>
            </tr>
        </thead>
        <tbody>
            <tr ng-repeat="item in data.rows" id="product_tr_{{item.id}}" ng-click="selectTr(item.id)" style="cursor:pointer">
                <td><input type="checkbox" name="product" value="{{item.id}}" /></td>
                <td><img ng-show="item.first_image != null||item.main_image_url != null" height="60" width="60" src="{{item.main_image_url!=null?item.main_image_url:item.first_image}}" /></td>
                <td>
                    <div class="media" style="width:200px;">
                        <div class="media-body">
                            <p class="media-heading">{{item.name}}</p>
                            <span>{{item.price | currency:'￥'}}</span>
                        </div>
                    </div>
                </td>
                <td>
                    <div style="overflow:hidden;white-space:nowrap;text-overflow:ellipsis;max-height:30px;width:280px;display:inline-block;">
                        {{item.short_description}}
                    </div>
                </td>
                <td>{{item.stock}}</td>
                <td>{{item.merchant.usertype == 2 || item.merchant.usertype == 5 ? '系统' : item.merchant.mobile}}</td>
                <td>{{item.sale_status == 0 ? '原始状态' : item.sale_status == 1 ? '出售中' : item.sale_status == 2 ? '仓库中' : item.sale_status == 3 ? '已删除' : '' }}</td>
                <td>{{item.audit_status == 1 ? '待审核' : item.audit_status == 2 ? '销售中' : item.audit_status == 3 ? '违规下架' : '' }}</td>
                <td>{{item.create_time}}</td>
            </tr>
        </tbody>
    </table>
    <div class="row">
        <div class="col-md-10">
            <uib-pagination total-items="data.total_result" items-per-page="data.size" ng-model="data.page" num-pages="list.total_pages"
                            ng-change="search_page(data.page)" class="pagination-sm" boundary-links="true" boundary-link-numbers="true" max-size="20"
                            previous-text="&lsaquo;" next-text="&rsaquo;" first-text="&laquo;" last-text="&raquo;"></uib-pagination>
            <span class="pull-right" style="margin: 30px 0px 20px 0px">共{{data.total_result}} 当前：{{data.page}}/{{data.total_pages}}</span>
        </div>
    </div>
    </p>
    <p class="modal-footer">
        <button class="btn btn-primary" ng-click="ok()">
            确认
        </button>
        <button class="btn btn-warning" ng-click="cancel()">
            退出
        </button>
    </p>
    </p>
</script>

<script type="text/ng-template" id="set_data.html">
    <div class="modal-header">
        <h3 class="modal-title">批量设置比例跟数量</h3>
    </div>
    <form name="_form" class="form-horizontal w5c-form" w5c-form-validate="model.validateOptions" role="form" novalidate>
        <div class="modal-body">
            <div class="form-group">
                <label class="col-sm-3 control-label">每单最小购买数</label>
                <div class="col-sm-4">
                    <input type="number" name="s_min_buy_mum" class="form-control input-sm" ng-model="setModel.s_min_buy_mum" step="1" min="1" required
                           onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">每单最大购买数</label>
                <div class="col-sm-4">
                    <input type="text" name="s_max_buy_num" class="form-control input-sm" ng-model="setModel.s_max_buy_num" step="1" min="0" required
                           onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^0-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^0-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">马力有效天数</label>
                <div class="col-sm-4">
                    <input type="text" name="s_horse_power_effective" class="form-control input-sm" ng-model="setModel.s_horse_power_effective" step="1" min="0" required
                           onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^0-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^0-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}">
                </div>
            </div>
        </div>
        <div class="modal-footer">
            <button class="btn btn-primary" type="submit" w5c-form-submit="saveSet()" btn-loading="psdisabled.save" loading-text="保存中..." ng-disabled="psdisabled.save">
                确定
            </button>
            <button class="btn btn-primary" type="button" ng-click="cancel()">取消</button>
        </div>
    </form>
</script>

<style type="text/css">
    .large-Modal .modal-dialog {
        height: 500px;
        width: 1000px;
        overflow-y: auto;
        overflow-x: hidden;
        /*margin: auto;
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;*/
    }

    .pop .modal-dialog {
        width: 500px;
        overflow-y: auto;
        overflow-x: hidden;
        height: 500px;
    }

    .ui-label {
        display: inline-block;
        width: 70px;
        text-align: right;
        padding: 0 10px 0 0;
        float: left;
        line-height: 30px;
    }

    .fn-hidden {
        overflow: hidden;
    }

    .popBox {
        padding: 30px
    }
</style>